package difangame.sprite;

import java.awt.Point;
import java.util.Random;
import difangame.Constants;
import framework.Level;
import framework.Sprite;


/**
 * 
 * @author difan, kathleen
 * 
 */

public class Stone extends Sprite {
    private int myXVelocity = 1;
    private final String myImageFile = "stone.jpg";
    private final int myWidth = 40;
    private final int myHeight = 15;
    private final int boardWidth = 300;
    private final int centerToEdge = 20;
    private boolean canHavePrize;
    private Sprite myPrize = null;

    @Override
    public void initialize (Point position, Level l) {
        super.superInitialize(position, myImageFile, myWidth, myHeight, l);
        setMyName(Constants.stone);  // magic number, will be fixed later
    }

    @Override
    protected void move () {
        super.getMyCenter().translate(myXVelocity, 0);
        if (getMyCenter().x + centerToEdge > boardWidth || getMyCenter().x < 0) {
            myXVelocity = 0 - myXVelocity;
        }
    }

    @Override
    protected void action () {
        if (canHavePrize) {
            Random generator = new Random();
            int addPrize = generator.nextInt(200);
            if (addPrize == 0) {
                initiatePrize();
            }
        }
    }

    public void setPrizeStatus (boolean status) {
        canHavePrize = status;
    }

    public void initiatePrize () {
        Prize p = new Prize();
        p.setMyCarrier(this);
        p.initialize(getMyCenter(), getMyLevel());
        myPrize = p;
    }

    public boolean hasPrize () {
        return myPrize != null;
    }

}
